<?php

namespace backend\models;
use yii\base\Model;
use yii\helpers\ArrayHelper;
use backend\models\TmeMerchandisecinfo;

class MerchandisForm extends Model {
	/*
	 * @商品信息
	 */
	//public $ID;                   //递增的流水号
	public $MerchandiseID;          //商品编码
	public $UnitID;                 //单位编码
	//public $ProStatusID;          //促销状态编码
	//public $MerchandiseCID;       //商品类别编码  
	public $MerchandiseName;        //商品名称
	public $MerchandiseAB;          //商品助记码
	public $Price;                  //商品价格  
	public $SaleStatus;             //销售状态  
	public $Spec;                   //规格
	public $Describes;              //商品描述
	public $PicPath;                //图片上传  
	public $ClickCount;             //点击数
	//public $Remark;               //备注
		
	/*
	 * @商品类别
	 */
    public $ID;                       
    public $MerchandiseCID;         //商品类别编码
    public $MerchandisePID;         //商品父id 
    public $MerchandiseCName;       //商品名称
    public $SortID;                 //排序编码
    public $State;                  //状态
    
    /*
     * @商品促销状态字典
     */
    public $ProStatusID;            //促销状态编码
    public $ProStatusName;          //促销状态名称 
    public $Status;                 //状态
    public $Remark;                 //备注
    
    /*
     * @商品单位字典
     */
	//public $UnitID;
	public $Name;
	//public $Status;
	//public $Remark;
    
    
    public function rules(){      
    	//$datamodel =  TmeMerchandisecinfo::find()->asArray()->where('ID != 0')->all();
    	//$listdata = ArrayHelper::map($datamodel,'ID','MerchandiseCName');
    	return[ 
    	       //商品分类   
	         [['ID','MerchandiseCID','MerchandisePID','MerchandiseCName'],'required','message'=>'{attribute}不能为空','on'=>'merchandisadd'],
	         ['ID','unique','targetClass'=>TmeMerchandisecinfo::className(),'targetAttribute'=>'ID','message'=>'{value}已存在','on'=>'merchandisadd'],
	         ['MerchandiseCID','string','max'=>8,'tooLong'=>'最大不能超过8位','on'=>'merchandisadd'],
	         ['MerchandisePID','string','on'=>'merchandisadd'],
	         ['MerchandiseCName','string','on'=>'merchandisadd'],
	         ['SortID','string','on'=>'merchandisadd'],
	         ['State','in','range'=>[0,1],'on'=>'merchandisadd'], 
    	      //商品促销规则 
    	     [['ProStatusName'],'required','message'=>'{attribute}不能为空！','on'=>'prostatusadd'],
    	     ['ProStatusID','string','max'=>8,'tooLong'=>'不能超过8位','message'=>'不能为空', 'on'=>'prostatusadd'],
    	     ['ProStatusName','string','message'=>'不能为空','on'=>'prostatusadd'],
    	     ['Status','in','range'=>[0,1],'message'=>'不能为空','on'=>'prostatusadd'],
    	     ['Remark','string','message'=>'不能为空','on'=>'prostatusadd'],
             //商品信息规则'MerchandiseCID','MerchandiseName',
    	     [['MerchandiseID','UnitID','ProStatusID','MerchandiseAB','Price','SaleStatus','Spec'],'required','message'=>'{attribute}不能为空','on'=>'merchandisinfoadd'],            
    	   	 ['MerchandiseID','unique','targetClass'=>TmeMerchandiseinfo::className(),'targetAttribute'=>'MerchandiseID','message'=>'商品编码不能重复！','on'=>'merchandisinfoadd'],
    	   	 ['UnitID','string','on'=>'merchandisinfoadd'],
    	   	 ['ProStatusID','string','on'=>'merchandisinfoadd'],
    	   	 ['MerchandiseCID','string','on'=>'merchandisinfoadd'],
    	   	 ['MerchandiseName','string','on'=>'merchandisinfoadd'],
    	   	 ['MerchandiseAB','string','on'=>'merchandisinfoadd'],
    	   	 ['Price','string','on'=>'merchandisinfoadd'],
    	   	 ['SaleStatus','in','range'=>[0,1],'message'=>'请正确选择销售状态','on'=>'merchandisinfoadd'],
    	   	 ['Spec','string','on'=>'merchandisinfoadd'],
    	   	 ['Describes','string','on'=>'merchandisinfoadd'],
    	   	 ['PicPath','file','extensions'=>'gif,jpg,png,jpeg','wrongExtension'=>'文件类型不正确','on'=>'upload'],  //文件上传
    	   	 ['ClickCount','integer','integerOnly'=>TRUE,'message'=>'点击量必须为整型','on'=>'merchandisinfoadd'],
    	   	 ['Remark','string','on'=>'merchandisinfoadd'],
    	   	 //商品单位字典规则
    	   	 [['Name'],'required','message'=>'{attribute}不能为空！','on'=>'unitinfo'],
    	   	 ['UnitID','string','on'=>'unitinfo'],
    	   	 ['Status','in','range'=>[0,1],'on'=>'unitinfo'],
    	   	 ['Remark','string','on'=>'unitinfo'],
    	];   	  	   	
    }
    
    //场景设置
    public function scenarios(){
    	return [
    		'prostatusadd'=>['ProStatusID','ProStatusName','Status','Remark'],                                  //商品促销添加场景设置
    		'prostatusmodify'=>['ProStatusID','ProStatusName','Status','Remark'],                               //商品促销修改场景设置
    		'merchandisadd'=>['ID','MerchandiseCID','MerchandisePID','MerchandiseCName','SortID','State'],      //添加商品分类场景
    		'merchandisupdate'=>['ID','MerchandiseCID','MerchandisePID','MerchandiseCName','SortID','State'],   //修改商品分类场景
    		'merchandisinfoadd'=>['ID','MerchandiseID','UnitID','ProStatusID','MerchandiseCID','MerchandiseName','MerchandiseAB','Price','SaleStatus','Spec','Describes','PicPath','ClickCount','Remark'],  //商品信息添加
    	    'upload'=>['PicPath'] ,
    	    'unitinfo'=>['UnitID','Name','Status','Remark']   	    
       ]; 
    }
    //属性的设置
    public function attributeLabels(){
        
    	return[
    	 //商品信息属性设置  
    	//'ID'=>'递增的流水号',                   
    	'MerchandiseID'=>'商品编码',         
    	'UnitID'=>'商品单位',                  
    	'ProStatusID'=>'促销活动',         
    	'MerchandiseCID'=>'商品类别编码',       
    	'MerchandiseName'=>'商品名称',        
    	'MerchandiseAB'=>'商品助记码',         
    	'Price'=>'商品价格',                  
    	'SaleStatus'=>'销售状态',           
    	'Spec'=>'规格',                 
    	'Describes'=>'商品描述',            
    	'PicPath'=>'上传图片',                
    	'ClickCount'=>'点击数',            
    	'Remark'=>'备注',              
    	
    	  //商品分类属性设置
	      'ID'=>'ID',
	      'MerchandiseCID'=>'商品类别编码',
	      'MerchandisePID'=>'商品父ID ',   
    	  'MerchandiseCName'=>'商品类别名称',
    	  'SortID'=>'排序编码',
    	  'State'=>'状态', 
    	  
    	  //商品促销状态字典
    	  'ProStatusID'=>'促销状态编码',
    	  'ProStatusName'=>'促销状态名称',
    	  'Status'=>'状态',
    	  'Remark'=>'备注',
    	  
    	  'Name'=>'商品单位名称'   	  
    	];    
    }             	
}

?>